home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / shells / tcshsrc.zoo / tcsh / sh.err.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-25  |  11.7 KB  |  457 lines

  1. /* $Header: /home/hyperion/mu/christos/src/sys/tcsh-6.00/RCS/sh.err.c,v 3.1 1991/07/15 19:37:24 christos Exp $ */
  2. /*
  3.  * sh.err.c: Error printing routines. There are lots of them
  4.  *         and none does the right thing!
  5.  */
  6. /*-
  7.  * Copyright (c) 1980, 1991 The Regents of the University of California.
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  * 3. All advertising materials mentioning features or use of this software
  19.  *    must display the following acknowledgement:
  20.  *    This product includes software developed by the University of
  21.  *    California, Berkeley and its contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  */
  38. #include "config.h"
  39. RCSID("$Id: sh.err.c,v 3.1 1991/07/15 19:37:24 christos Exp $")
  40.  
  41. #define _h_tc_err        /* Don't redefine the errors     */
  42. #include "sh.h"
  43.  
  44. /*
  45.  * C Shell
  46.  */
  47.  
  48. char   *seterr = NULL;    /* Holds last error if there was one */
  49.  
  50. #define ERR_FLAGS    0xf0000000
  51. #define ERR_NAME    0x10000000
  52. #define ERR_SILENT    0x20000000
  53. #define ERR_OLD        0x40000000
  54.  
  55. static char *errorlist[] = 
  56. {
  57. #define ERR_SYNTAX    0
  58.     "Syntax Error",
  59. #define ERR_NOTALLOWED    1
  60.     "%s is not allowed",
  61. #define ERR_WTOOLONG    2
  62.     "Word too long",
  63. #define ERR_LTOOLONG    3
  64.     "$< line too long",
  65. #define ERR_DOLZERO    4
  66.     "No file for $0",
  67. #define ERR_DOLQUEST    5
  68.     "$? not allowed here",
  69. #define ERR_INCBR    6
  70.     "Incomplete [] modifier",
  71. #define ERR_EXPORD    7
  72.     "$ expansion must end before ]",
  73. #define ERR_BADMOD    8
  74.     "Bad : modifier in $ (%c)",
  75. #define ERR_SUBSCRIPT    9
  76.     "Subscript error",
  77. #define ERR_BADNUM    10
  78.     "Badly formed number",
  79. #define ERR_NOMORE    11
  80.     "No more words",
  81. #define ERR_FILENAME    12
  82.     "Missing file name",
  83. #define ERR_GLOB    13
  84.     "Internal glob error",
  85. #define ERR_COMMAND    14
  86.     "Command not found",
  87. #define ERR_TOOFEW    15
  88.     "Too few arguments",
  89. #define ERR_TOOMANY    16
  90.     "Too many arguments",
  91. #define ERR_DANGER    17
  92.     "Too dangerous to alias that",
  93. #define ERR_EMPTYIF    18
  94.     "Empty if",
  95. #define ERR_IMPRTHEN    19
  96.     "Improper then",
  97. #define ERR_NOPAREN    20
  98.     "Words not parenthesized",
  99. #define ERR_NOTFOUND    21
  100.     "%s not found",
  101. #define ERR_MASK    22
  102.     "Improper mask",
  103. #define ERR_LIMIT    23
  104.     "No such limit",
  105. #define ERR_TOOLARGE    24
  106.     "Argument too large",
  107. #define ERR_SCALEF    25
  108.     "Improper or unknown scale factor",
  109. #define ERR_UNDVAR    26
  110.     "Undefined variable",
  111. #define ERR_DEEP    27
  112.     "Directory stack not that deep",
  113. #define ERR_BADSIG    28
  114.     "Bad signal number",
  115. #define ERR_UNKSIG    29
  116.     "Unknown signal; kill -l lists signals",
  117. #define ERR_VARBEGIN    30
  118.     "Variable name must begin with a letter",
  119. #define ERR_VARTOOLONG    31
  120.     "Variable name too long",
  121. #define ERR_VARALNUM    32
  122.     "Variable name must contain alphanumeric characters",
  123. #define ERR_JOBCONTROL    33
  124.     "No job control in this shell",
  125. #define ERR_EXPRESSION    34
  126.     "Expression Syntax",
  127. #define ERR_NOHOMEDIR    35
  128.     "No home directory",
  129. #define ERR_CANTCHANGE    36
  130.     "Can't change to home directory",
  131. #define ERR_NULLCOM    37
  132.     "Invalid null command",
  133. #define ERR_ASSIGN    38
  134.     "Assignment missing expression",
  135. #define ERR_UNKNOWNOP    39
  136.     "Unknown operator",
  137. #define ERR_AMBIG    40
  138.     "Ambiguous",
  139. #define ERR_EXISTS    41
  140.     "%s: File exists",
  141. #define ERR_ARGC    42
  142.     "Argument for -c ends in backslash",
  143. #define ERR_INTR    43
  144.     "Interrupted",
  145. #define ERR_RANGE    44
  146.     "Subscript out of range",
  147. #define ERR_OVERFLOW    45
  148.     "Line overflow",
  149. #define ERR_NOSUCHJOB    46
  150.     "No such job",
  151. #define ERR_TERMINAL    47
  152.     "Can't from terminal",
  153. #define ERR_NOTWHILE    48
  154.     "Not in while/foreach",
  155. #define ERR_NOPROC    49
  156.     "No more processes",
  157. #define ERR_NOMATCH    50
  158.     "No match",
  159. #define ERR_MISSING    51
  160.     "Missing %c",
  161. #define ERR_UNMATCHED    52
  162.     "Unmatched %c",
  163. #define ERR_NOMEM    53
  164.     "Out of memory",
  165. #define ERR_PIPE    54
  166.     "Can't make pipe",
  167. #define ERR_SYSTEM    55
  168.     "%s: %s",
  169. #define ERR_STRING    56
  170.     "%s",
  171. #define ERR_JOBS    57
  172.     "Usage: jobs [ -l ]",
  173. #define ERR_JOBARGS    58
  174.     "Arguments should be jobs or process id's",
  175. #define ERR_JOBCUR    59
  176.     "No current job",
  177. #define ERR_JOBPREV    60
  178.     "No previous job",
  179. #define ERR_JOBPAT    61
  180.     "No job matches pattern",
  181. #define ERR_NESTING    62
  182.     "Fork nesting > %d; maybe `...` loop",
  183. #define ERR_JOBCTRLSUB    63
  184.     "No job control in subshells",
  185. #define ERR_SYNC    64
  186.     "Sunc fault: Process %d not found",
  187. #define ERR_STOPPED    65
  188. #ifdef SUSPENDED
  189.     "%sThere are suspended jobs",
  190. #else
  191.     "%sThere are stopped jobs",
  192. #endif                /* SUSPENDED */
  193. #define ERR_NODIR    66
  194.     "No other directory",
  195. #define ERR_EMPTY    67
  196.     "Directory stack empty",
  197. #define ERR_BADDIR    68
  198.     "Bad directory",
  199. #define ERR_DIRUS    69
  200.     "Usage: %s [-lvn]%s",
  201. #define ERR_HFLAG    70
  202.     "No operand for -h flag",
  203. #define ERR_NOTLOGIN    71
  204.     "Not a login shell",
  205. #define ERR_DIV0    72
  206.     "Division by 0",
  207. #define ERR_MOD0    73
  208.     "Mod by 0",
  209. #define ERR_BADSCALE    74
  210.     "Bad scaling; did you mean \"%s\"?",
  211. #define ERR_SUSPLOG    75
  212.     "Can't suspend a login shell (yet)",
  213. #define ERR_UNKUSER    76
  214.     "Unknown user: %s",
  215. #define ERR_NOHOME    77
  216.     "No $home variable set",
  217. #define ERR_HISTUS    78
  218.     "Usage: history [-rht] [# number of events]",
  219. #define ERR_SPDOLLT    79
  220.     "$ or < not allowed with $# or $?",
  221. #define ERR_NEWLINE    80
  222.     "Newline in variable name",
  223. #define ERR_SPSTAR    81
  224.     "* not allowed with $# or $?",
  225. #define ERR_DIGIT    82
  226.     "$?<digit> or $#<digit> not allowed",
  227. #define ERR_VARILL    83
  228.     "Illegal variable name",
  229. #define ERR_NLINDEX    84
  230.     "Newline in variable index",
  231. #define ERR_EXPOVFL    85
  232.     "Expansion buffer overflow",
  233. #define ERR_VARSYN    86
  234.     "Variable syntax",
  235. #define ERR_BADBANG    87
  236.     "Bad ! form",
  237. #define ERR_NOSUBST    88
  238.     "No previous substitute",
  239. #define ERR_BADSUBST    89
  240.     "Bad substitute",
  241. #define ERR_LHS        90
  242.     "No previous left hand side",
  243. #define ERR_RHSLONG    91
  244.     "Right hand side too long",
  245. #define ERR_BADBANGMOD    92
  246.     "Bad ! modifier: %c",
  247. #define ERR_MODFAIL    93
  248.     "Modifier failed",
  249. #define ERR_SUBOVFL    94
  250.     "Substitution buffer overflow",
  251. #define ERR_BADBANGARG    95
  252.     "Bad ! arg selector",
  253. #define ERR_NOSEARCH    96
  254.     "No prev search",
  255. #define ERR_NOEVENT    97
  256.     "%s: Event not found",
  257. #define ERR_TOOMANYRP    98
  258.     "Too many )'s",
  259. #define ERR_TOOMANYLP    99
  260.     "Too many ('s",
  261. #define ERR_BADPLP    100
  262.     "Badly placed (",
  263. #define ERR_MISRED    101
  264.     "Missing name for redirect",
  265. #define ERR_OUTRED    102
  266.     "Ambiguous output redirect",
  267. #define ERR_REDPAR    103
  268.     "Can't << within ()'s",
  269. #define ERR_INRED    104
  270.     "Ambiguous input redirect",
  271. #define ERR_BADPLPS    105
  272.     "Badly placed ()'s",
  273. #define ERR_VARMOD    106
  274.     "Unknown variable modifier",
  275. #define ERR_ALIASLOOP    107
  276.     "Alias loop",
  277. #define ERR_NOWATCH    108
  278.     "No $watch variable set",
  279. #define ERR_NOSCHED    109
  280.     "No scheduled events",
  281. #define ERR_SCHEDUSAGE    110
  282.     "Usage: sched -<item#>.\nUsage: sched [+]hh:mm <command>",
  283. #define ERR_SCHEDEV    111
  284.     "Not that many scheduled events",
  285. #define ERR_SCHEDCOM    112
  286.     "No command to run",
  287. #define ERR_SCHEDTIME    113
  288.     "Invalid time for event",
  289. #define ERR_SCHEDREL    114
  290.     "Relative time inconsistent with am/pm",
  291. #define ERR_TCNOSTR    115
  292.     "Out of termcap string space",
  293. #define ERR_SETTCUS    116
  294.     "Usage: settc %s [yes|no]",
  295. #define ERR_TCCAP    117
  296.     "Unknown capability `%s'",
  297. #define ERR_TCPARM    118
  298.     "Unknown termcap parameter `%%%c'",
  299. #define ERR_TCARGS    119
  300.     "Too many arguments for `%s' (%d)",
  301. #define ERR_TCNARGS    120
  302.     "`%s' requires %d arguments",
  303. #define ERR_TCUSAGE    121
  304.     "Usage: echotc [-v|-s] [<capability> [<args>]]",
  305. #define ERR_ARCH    122
  306.     "%s: %s. Wrong Architecture",
  307. #define ERR_HISTLOOP    123
  308.     "!# History loop",
  309. #define ERR_FILEINQ    124
  310.     "Malformed file inquiry",
  311. #define ERR_SELOVFL    125
  312.     "Selector overflow",
  313. #define ERR_INVALID    126
  314.     "Invalid Error"
  315. };
  316.  
  317. /*
  318.  * The parser and scanner set up errors for later by calling seterr,
  319.  * which sets the variable err as a side effect; later to be tested,
  320.  * e.g. in process.
  321.  */
  322. void
  323. /*VARARGS1*/
  324. #if __STDC__
  325. seterror(int id, ...)
  326. #else
  327. seterror(va_alist)
  328.     va_dcl
  329. #endif
  330. {
  331.  
  332.     if (seterr == 0) {
  333.     va_list va;
  334.     char    berr[BUFSIZ];
  335. #if __STDC__
  336.     va_start(va, id);
  337. #else
  338.     int id;
  339.     va_start(va);
  340.     id = va_arg(va, int);
  341. #endif
  342.  
  343.     if (id < 0 || id > sizeof(errorlist) / sizeof(errorlist[0]))
  344.         id = ERR_INVALID;
  345.     xvsprintf(berr, errorlist[id], va);
  346.     va_end(va);
  347.  
  348.     seterr = strsave(berr);
  349.     }
  350. }
  351.  
  352. /*
  353.  * Print the error with the given id.
  354.  *
  355.  * Special ids:
  356.  *    ERR_SILENT: Print nothing.
  357.  *    ERR_OLD: Print the previously set error if one was there.
  358.  *             otherwise return.
  359.  *    ERR_NAME: If this bit is set, print the name of the function
  360.  *          in bname
  361.  *
  362.  * This routine always resets or exits.  The flag haderr
  363.  * is set so the routine who catches the unwind can propogate
  364.  * it if they want.
  365.  *
  366.  * Note that any open files at the point of error will eventually
  367.  * be closed in the routine process in sh.c which is the only
  368.  * place error unwinds are ever caught.
  369.  */
  370. void
  371. /*VARARGS*/
  372. #if __STDC__
  373. stderror(int id, ...)
  374. #else
  375. stderror(va_alist)
  376.     va_dcl
  377. #endif
  378. {
  379.     va_list va;
  380.     register Char **v;
  381.     int     flags;
  382.  
  383. #if __STDC__
  384.     va_start(va, id);
  385. #else
  386.     int        id;
  387.  
  388.     va_start(va);
  389.     id = va_arg(va, int);
  390. #endif
  391.  
  392.     flags = id & ERR_FLAGS;
  393.     id &= ~ERR_FLAGS;
  394.  
  395.     if ((flags & ERR_OLD) && seterr == NULL) {
  396.     va_end(va);
  397.     return;
  398.     }
  399.  
  400.     if (id < 0 || id > sizeof(errorlist) / sizeof(errorlist[0]))
  401.     id = ERR_INVALID;
  402.  
  403.     /*
  404.      * Must flush before we print as we wish output before the error to go on
  405.      * (some form of) standard output, while output after goes on (some form
  406.      * of) diagnostic output. If didfds then output will go to 1/2 else to
  407.      * FSHOUT/FSHDIAG. See flush in sh.print.c.
  408.      */
  409.     flush();
  410.     haderr = 1;            /* Now to diagnostic output */
  411.     timflg = 0;            /* This isn't otherwise reset */
  412.  
  413.  
  414.     if (!(flags & ERR_SILENT)) {
  415.     if (flags & ERR_NAME)
  416.         xprintf("%s: ", bname);
  417.     if ((flags & ERR_OLD))
  418.         /* Old error. */
  419.         xprintf("%s.\n", seterr);
  420.     else {
  421.         xvprintf(errorlist[id], va);
  422.         xprintf(".\n");
  423.     }
  424.     }
  425.     va_end(va);
  426.  
  427.     if (seterr) {
  428.     xfree((ptr_t) seterr);
  429.     seterr = NULL;
  430.     }
  431.  
  432.     if (v = pargv)
  433.     pargv = 0, blkfree(v);
  434.     if (v = gargv)
  435.     gargv = 0, blkfree(v);
  436.  
  437.     didfds = 0;            /* Forget about 0,1,2 */
  438.     /*
  439.      * Go away if -e or we are a child shell
  440.      */
  441.     if (exiterr || child)
  442.     xexit(1);
  443.  
  444.     /*
  445.      * Reset the state of the input. This buffered seek to end of file will
  446.      * also clear the while/foreach stack.
  447.      */
  448.     btoeof();
  449.  
  450.     set(STRstatus, Strsave(STR1));
  451. #ifdef BSDJOBS
  452.     if (tpgrp > 0)
  453.     (void) tcsetpgrp(FSHTTY, tpgrp);
  454. #endif
  455.     reset();            /* Unwind */
  456. }
  457.